import { Controller, Get, UseGuards } from '@nestjs/common';
import { RedisService } from '@/services/redis.service';
import { JwtAuthGuard } from '@/guards/jwt-auth.guard';

@Controller('redis')
export class RedisController {
    constructor(private readonly redisService: RedisService) {}

    @Get('stats')
    async getStats() {
        const stats = await this.redisService.getStats();
        return {
            message: 'Redis 统计信息',
            data: stats,
            timestamp: new Date().toISOString(),
        };
    }

    @Get('ping')
    async ping() {
        return await this.redisService.getStats();
    }

    @UseGuards(JwtAuthGuard)
    @Get('flush')
    async flushAll() {
        await this.redisService.flushAll();
        return {
            message: 'Redis 缓存已清空',
            timestamp: new Date().toISOString(),
        };
    }
}
